/*
 * Copyright (c) 2006, 2007 FTS Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the FTS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      BitIndex.hpp
 *
 * $FTS$
 */
#ifndef _BIT_INDEX_HPP__
#define _BIT_INDEX_HPP__ 1

/**
  @file BitIndex.hpp
  @brief Bit index storage
*/

#include <FTSTypes.h>

#include <stdlib.h>

namespace FTSS // FullTextSearchSystem
{

/**
  @class BitIndex BitIndex.hpp <BitIndex.hpp>
  @brief Bit index storage
*/
class BitIndex
{
public:
	/**
	  @brief A constructor
	  @param iStartChunkSize - index chunk size
	*/
	inline BitIndex(INT_32 iStartChunkSize = 0): iMaxChunkSize(iStartChunkSize), iUsedChunkSize(0), pChunk(NULL)
	{
		if (iMaxChunkSize == 0) { iMaxChunkSize = 1; }

		pChunk = (CHAR_8 *)::operator new(sizeof(CHAR_8) * iMaxChunkSize);
	}

	/**
	  @brief Set bit at specified offset
	  @param iOffset - bit offset
	  @param iBit - Bit value
	*/
	inline void SetBit(INT_32 iOffset, INT_32 iBit)
	{
		iOffset = iOffset >> 8;

		if (iOffset > iMaxChunkSize) { ResizeIndex(iOffset); }

		INT_32 iPos = iOffset % 8;
		CHAR_8 iTMP = pChunk[iOffset];
		switch (iPos)
		{
			case 0x01:
				;;
				break;
			case 0x02:
				;;
				break;
			case 0x04:
				;;
				break;
			case 0x08:
				;;
				break;
			case 0x10:
				;;
				break;
			case 0x20:
				;;
				break;
			case 0x40:
				;;
				break;
			case 0x80:
				;;
				break;

		}

//		INT_32 iChunkNum = iOffset / iChunkSize / sizeof(UCHAR_8);
	}

	/**
	  @brief Set block of bits at specified offset
	  @param iOffset - Bit offset
	  @param iNBits - Number of bits
	  @param iBits - Bits to set
	  @param iDestinationOffset - Offset in source word
	*/
	inline void SetNBits(INT_32 iOffset, INT_32 iNBits, INT_32 iBits, INT_32 iDestinationOffset = 0)
	{
		;;
	}

	/**
	  @brief Get bit from specified offset
	  @param iOffset - bit offset
	  @return Bit value
	*/
	inline INT_32 GetBit(INT_32 iOffset)
	{
		return 0;
	}

	/**
	  @brief Get block of bits from specified offset
	  @param iOffset - Bit offset
	  @param iNBits - Number of bits
	  @param iDestinationOffset - Offset in source word
	*/
	inline INT_32 GetNBits(INT_32 iOffset, INT_32 iNBits, INT_32 iDestinationOffset = 0)
	{
		return 0;
	}

	/**
	  @brief A destructor
	*/
	inline ~BitIndex() throw()
	{
		::operator delete pChunk;
	}

private:
	/** Chunk size        */
	INT_32       iMaxChunkSize;
	/** Number of chunks  */
	INT_32       iUsedChunkSize;
	/** Current chunk     */
	UCHAR_8    * pChunk;
};

} // namespace FTSS
#endif // _BIT_INDEX_HPP__
// End.
